package com.september.util;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;

import com.september.main.Runner;
import com.september.prop.Properteer;


public class Reader {

	/**
	 * @param <T>
	 * @param args
	 */
	
	public static <T extends BaseData> List<T>  read(T type, String fileName, String[] orders) {
	
		List<T> geoBean = new LinkedList<T>();
		
		InputStream is = 	Runner.class.getClassLoader().getResourceAsStream(fileName);
		
		DataInputStream in = new DataInputStream(is);
		  BufferedReader br = new BufferedReader(new InputStreamReader(in));
		  String strLine;
		  //Read File Line By Line
		  try {
			while ((strLine = br.readLine()) != null)   {
				T bean = (T) type.getClass().newInstance().fromLine(strLine, orders);
				if(bean != null)
					geoBean.add(bean);
			  }
			br.close();
			in.close();
		  }
			catch (Exception e) {
				Properteer.getInstance().getLogger(Reader.class).error(e.getClass().getName(),e);
			}
			
			return geoBean;
	}

}
